<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Move\Controller;

/**
 * Description of IndexController
 *
 * @author gc
 */
class IndexController extends CommonController
{

    //首页

    public function index()
    {

        $map['introducer_id'] = $this->uid;
        $list = M("Student")->where($map)->order("id desc")->select();
        $this->assign("_list", $list);

        $this->meta_title = '学生列表';

        $this->display();
    }

    //加载更多
    public function loadMore()
    {
//        $p = I("p", 2);
//        $model = D('CouponView');
//        $list = $model->getList($p, $this->len);
//        $status = count($list) > 0 ? 1 : 0;
//        $this->ajaxReturn(array('status' => $status, 'data' => $list));
    }

    //创建优惠券
    public function add()
    {
        $this->meta_title = "学生录入";
        $this->display();
    }

    public function save()
    {
        $post = I("post.");

        if (empty($post['name'])) {
            $this->error('学生姓名不能为空！');
        }

        $map['name'] = $post['name'];
        $rs = M("Student")->where($map)->find();
        if (empty($rs)) {
            $post['birthday'] = strtotime($post['birthday']);
            $post['introducer_id'] = $this->uid;
            $post['status'] = 1;
            $post['create_time'] = $post['update_time'] = time();
            $rs = M("Student")->add($post);
            $rs ? $this->success('创建成功！', U('index')) : $this->error('创建失败！');
        }
        $this->error('该学生已存在！');
    }

}
